<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //定义数组
        let arr = [10, 20]
        console.log("arr", arr)


        //push：向数组末尾添加一个或多个元素，返回数组长度
        let arrLength = arr.push(5, 9)
        console.log("arr", arr)
        console.log("arrLength", arrLength)

        //unshift:添加数组里开头一个或多个元素，返回数组长度
        arrLength = arr.unshift(5, 7)
        console.log("arr", arr)
        console.log("arrLength", arrLength)


        //shift：删除数组第一个元素，并返回被删除元素
        let delteletment = arr.shift()
        console.log("arr", arr)
        console.log("delteletment", delteletment)

        //pop:删除最后一个元素，并返回被删除元素
        delteletment = arr.pop()
        console.log("arr", arr)
        console.log("delteletment", delteletment)
        //splice:删除某个元素，并返回被删除元素的数组(索引位置，要删除元素的数量)
        let arr1 = [1, 2, 3, 4]
        delarr = arr1.splice(1, 2)
        console.log("delarr", delarr)
        console.log("arr1", arr1)


        //reverse:颠倒元素的顺序
        let uarr = [6, 7, 11, 9, 10]
        unarr = uarr.reverse()
        console.log("uarr", uarr)

        //sort:数组中的元素按照首字母排序
        let arr3 = ["banna", "apple", "egg"]
        sarr = arr3.sort()
        console.log("sarr", sarr)

        //sort((a,b)=>a-b):数组中的元素按照从大到小排序
        uarr.sort((a, b) => a - b)
        console.log("uarr", uarr)

        //filter:筛选符合条件的返回一个新的数组arr.filter((vaule) => {条件})    
        let arr4 = [5, 7, 8, 9, 12, 14, 16, 18]
        arr5 = arr4.filter((vaule) => {
            return vaule > 9
        })
        console.log("arr5", arr5)

        //利用for遍历数组for (let vaule of arr) {console.log(vaule)}
        let arr6 = ["单欣烁", 19, "String"]
        for (let vaule of arr6) {
            console.log("arr6", vaule)
        }
        //利用forEach遍历数组arr.forEach(vaule => {console.log("forEach", vaule) })
        arr6.forEach(vaule => {
            console.log("forEach", vaule)
        })
        //利用forEach遍历数组,并返回对应下标
        arr6.forEach((vaule, index) => {
            console.log("forEach", vaule, "forEach", index)
        })
        //好难啊！！！！
    </script>
</body>

</html>